﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

namespace com.orange.examination
{
    public partial class WebForm12 : System.Web.UI.Page
    {
        private static int id;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
            {
                Response.Redirect("../LoginAndRegister/Login.aspx");
            }
            else 
            if (!IsPostBack)
            {
                id = Convert.ToInt32(Request.QueryString["Eid"]);
                MySqlConnection conn = BaseClass.DBCon();
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("select * from tb_test where ID=" + id, conn);
                MySqlDataReader sdr = cmd.ExecuteReader(); sdr.Read();
                txtsubject.Text = sdr["testContent"].ToString();
                txtAnsA.Text = sdr["testAns1"].ToString();
                txtAnsB.Text = sdr["testAns2"].ToString();
                txtAnsC.Text = sdr["testAns3"].ToString();
                txtAnsD.Text = sdr["testAns4"].ToString();
                rblRightAns.SelectedValue = sdr["rightAns"].ToString();
                string fb = sdr["pub"].ToString();
                if (fb == "1")
                    cbFB.Checked = true;
                else
                    cbFB.Checked = false;
                lblkm.Text = sdr["testCourse"].ToString();
                sdr.Close();
                conn.Close();
            }
        }

        protected void btnconfirm_Click(object sender, EventArgs e)
        {
            if (txtsubject.Text == "" || txtAnsA.Text == "" || txtAnsB.Text == "" ||
                txtAnsC.Text == "" || txtAnsD.Text == "")
            {
                Response.Write("<script type=text/javascript>alert('请将信息输入完整！')</script>");
                return;
            }
            else
            {
                string isfb = "";
                if (cbFB.Checked == true)
                    isfb = "1";
                else
                    isfb = "0";

                string str = "update tb_text set testContent='" + txtsubject.Text.Trim() + "',textAns1='"
                    + txtAnsA.Text.Trim() + "',textAns2='" + txtAnsB.Text.Trim() + "',textAns3='"
                    + txtAnsC.Text.Trim() + "',textAns4='" + txtAnsD.Text + "',rightAns='"
                    + rblRightAns.SelectedValue.ToString() + "',pub='" + isfb + "'where ID=" + id;
                BaseClass.OperateData(str);
                Response.Redirect("ExaminationInfo.aspx");
            }
        }
        protected void btnconcel_Click(object sender, EventArgs e)
        {
            Response.Redirect("ExaminationInfo.aspx");
        }
    }
}